import React, {Component} from 'react'
import {withRouter} from 'react-router-dom'
import {Button} from "antd";

 class JumpBtns extends Component {
    pushPage=()=>{
        // this.props.history.push('/home/push传递的params')
        // this.props.history.push('/about?name=push传递的search&age=5')
        this.props.history.push('/other',{name:'push传递的state',age:5})
    }
    replacePage=()=>{
        this.props.history.replace('/home/place传递的params')
        // this.props.history.replace('/about?name=place传递的search&age=5')
        // this.props.history.replace('/other',{name:'place传递的state',age:5})
    }
    render() {
        return (
            <div>
                <h2>编程式路由跳转</h2>
                <h4>路由组件本身会携带路由跳转api在props上，一般组件需要使用withRouter</h4>
                <Button type='primary' onClick={this.pushPage}>push</Button>
                <Button type='primary' onClick={this.replacePage}>replace</Button>
            </div>
        )
    }
}

export default  withRouter(JumpBtns)
